<?php
echo $header;
echo $column_left;
echo $column_right;
$width_content = '98%';
if (($column_left) && ($column_right)) {
    $width_content = '48%';
} elseif (($column_left) || ($column_right)) {
    $width_content = '73%';
}
?>
<div class="content" style="width:<?php echo $width_content; ?>"><?php echo $content_top; ?>
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <ul data-role="listview" data-divider-theme="a" data-inset="true">
        <li data-role="list-divider"><h1><?php echo $heading_title; ?></h1></li>
    </ul><br />
    <?php if ($error_warning) { ?>
        <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <p><?php echo $text_account_already; ?></p>
    <p><?php echo $text_signup; ?></p>
    <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="register">
        <div class="form">
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_your_details; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_firstname; ?>" type="text" name="firstname" value="<?php echo $firstname; ?>" /><span class="required">*</span>
                        <?php if ($error_firstname) { ?>
                            <div class="error"><?php echo $error_firstname; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_lastname; ?>" type="text" name="lastname" value="<?php echo $lastname; ?>" /><span class="required">*</span>
                        <?php if ($error_lastname) { ?>
                            <div class="error"><?php echo $error_lastname; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_email; ?>" type="text" name="email" value="<?php echo $email; ?>" /><span class="required">*</span>
                        <?php if ($error_email) { ?>
                            <div class="error"><?php echo $error_email; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_telephone; ?>" type="text" name="telephone" value="<?php echo $telephone; ?>" /><span class="required">*</span>
                        <?php if ($error_telephone) { ?>
                            <div class="error"><?php echo $error_telephone; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_fax; ?>" type="text" name="fax" value="<?php echo $fax; ?>" />
                    </li>
                </ul>
            </div>
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_your_address; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_company; ?>" type="text" name="company" value="<?php echo $company; ?>" /><span class="required">*</span>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_website; ?>" type="text" name="website" value="<?php echo $website; ?>" /><span class="required">*</span>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_address_1; ?>" type="text" name="address_1" value="<?php echo $address_1; ?>" /><span class="required">*</span>
                        <?php if ($error_address_1) { ?>
                            <div class="error"><?php echo $error_address_1; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_address_2; ?>" type="text" name="address_2" value="<?php echo $address_2; ?>" /><span class="required">*</span>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_city; ?>" type="text" name="city" value="<?php echo $city; ?>" /><span class="required">*</span>
                        <?php if ($error_city) { ?>
                            <div class="error"><?php echo $error_city; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_postcode; ?>" type="text" name="postcode" value="<?php echo $postcode; ?>" /><span class="required" id="postcode-required">*</span>
                        <?php if ($error_postcode) { ?>
                            <div class="error"><?php echo $error_postcode; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <label for="country_id"><span class="required">*</span> <?php echo $entry_country; ?></label>
                        <select name="country_id" id="country_id" class="large-field">
                            <option value=""><?php echo $text_select; ?></option>
                            <?php foreach ($countries as $country) { ?>
                                <option value="<?php echo $country['country_id']; ?>"<?php echo ($country['country_id'] == $country_id ? ' selected="selected"' : ''); ?>><?php echo $country['name']; ?></option>
                            <?php } ?>
                        </select>
                        <?php if ($error_country) { ?>
                            <div class="error"><?php echo $error_country; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <label for="zone_id"><span class="required">*</span> <?php echo $entry_zone; ?></label>
                        <select name="zone_id" id="zone_id" class="large-field">
                        </select>
                        <?php if ($error_zone) { ?>
                            <div class="error"><?php echo $error_zone; ?></div>
                        <?php } ?>
                    </li>
                </ul>
            </div>

            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_payment; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_tax; ?>" type="text" name="tax" value="<?php echo $tax; ?>" />
                    </li>
                    <li>
                        <fieldset data-role="controlgroup">
                            <legend><?php echo $entry_payment; ?></legend>
                            <input type="radio" name="payment" value="cheque" id="cheque"<?php echo ($payment == 'cheque' ? ' checked="checked"' : ''); ?> /><label for="cheque"><?php echo $text_cheque; ?></label>
                            <input type="radio" name="payment" value="paypal" id="paypal"<?php echo ($payment == 'paypal' ? ' checked="checked"' : ''); ?> /><label for="paypal"><?php echo $text_paypal; ?></label>
                            <input type="radio" name="payment" value="bank" id="bank"<?php echo ($payment == 'bank' ? ' checked="checked"' : ''); ?> /><label for="bank"><?php echo $text_bank; ?></label>
                        </fieldset>
                    </li>
                </ul>
                <ul data-role="listview" data-divider-theme="a" data-inset="true" id="payment-cheque" class="payment">
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_cheque; ?>" type="text" name="cheque" value="<?php echo $cheque; ?>" />
                    </li>
                </ul>
                <ul data-role="listview" data-divider-theme="a" data-inset="true" id="payment-paypal" class="payment">
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_paypal; ?>" type="text" name="paypal" value="<?php echo $paypal; ?>" />
                    </li>
                </ul>
                <ul data-role="listview" data-divider-theme="a" data-inset="true" id="payment-bank" class="payment">
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_bank_name; ?>" type="text" name="bank_name" value="<?php echo $bank_name; ?>" />
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_bank_branch_number; ?>" type="text" name="bank_branch_number" value="<?php echo $bank_branch_number; ?>" />
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_bank_swift_code; ?>" type="text" name="bank_swift_code" value="<?php echo $bank_swift_code; ?>" />
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_bank_account_name; ?>" type="text" name="bank_account_name" value="<?php echo $bank_account_name; ?>" />
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_bank_account_number; ?>" type="text" name="bank_account_number" value="<?php echo $bank_account_number; ?>" />
                    </li>
                </ul>
            </div>
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_your_password; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_password; ?>" type="password" name="password" value="<?php echo $password; ?>" /><span class="required">*</span>
                        <?php if ($error_password) { ?>
                            <div class="error"><?php echo $error_password; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_confirm; ?>" type="password" name="confirm" value="<?php echo $confirm; ?>" /><span class="required">*</span>
                        <?php if ($error_confirm) { ?>
                            <div class="error"><?php echo $error_confirm; ?></div>
                        <?php } ?>
                    </li>
                </ul>
            </div>
        </div>
        <div class="buttons">
            <div class="right">
                <?php if ($text_agree) { ?>
                    <label for="agree">&nbsp;</label><?php echo strtr($text_agree, array('<a' => '<a data-rel="dialog"')); ?>
                    <?php if ($agree) { ?>
                        <input type="checkbox" id="agree" name="agree" value="1" checked="checked" />
                    <?php } else { ?>
                        <input type="checkbox" id="agree" name="agree" value="1" />
                    <?php }
                }
                ?>
                <a data-role="button" onclick="$('#register').submit();" class="button"><span><?php echo $button_continue; ?></span></a>
            </div>
        </div>
    </form>
<?php echo $content_bottom; ?>
</div>
<script type="text/javascript"><!--
    $('select[name=\'country_id\']').bind('change', function() {
        $.ajax({
            url: 'index.php?route=affiliate/register/country&country_id=' + this.value,
            dataType: 'json',
            beforeSend: function() {
                $('select[name=\'country_id\']').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
            },
            complete: function() {
                $('.wait').remove();
            },
            success: function(json) {
                if (json['postcode_required'] == '1') {
                    $('#postcode-required').show();
                } else {
                    $('#postcode-required').hide();
                }

                html = '<option value=""><?php echo $text_select; ?></option>';

                if (json['zone'] != '') {
                    for (i = 0; i < json['zone'].length; i++) {
                        html += '<option value="' + json['zone'][i]['zone_id'] + '"';

                        if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
                            html += ' selected="selected"';
                        }

                        html += '>' + json['zone'][i]['name'] + '</option>';
                    }
                } else {
                    html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
                }

                $('select[name=\'zone_id\']').html(html);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    });

    $('select[name=\'country_id\']').trigger('change');
    //--></script>
<script type="text/javascript"><!--
    $('input[name=\'payment\']').bind('change', function() {
        $('.payment').hide();

        $('#payment-' + this.value).show();
    });

    $('input[name=\'payment\']:checked').trigger('change');
    //--></script>
<?php echo $footer; ?>